{template header}

<link href="{SITE_URL}public/bootstrap-datetimepicker/bootstrap-datetimepicker.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="{SITE_URL}public/bootstrap-datetimepicker/bootstrap-datetimepicker.js" charset="UTF-8"></script>
<script type="text/javascript" src="{SITE_URL}public/bootstrap-datetimepicker/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>


<div class="container">


<ol class="breadcrumb">
  <li><a href="{SITE_URL}">首页</a></li>
  <li><a href="{tsUrl('wish')}">心愿</a></li>
  <li><a href="{tsUrl('wish','show',array('id'=>$strWish[wishid]))}">{$strWish['title']}</a></li>
  <li class="active">修改心愿</li>
</ol>



<div class="panel panel-default">
  <div class="panel-body">
  



<div class="row">
  <div class="col-md-2"></div>
  <div class="col-md-8">
  
  <form method="POST" action="{SITE_URL}index.php?app=wish&ac=edit&ts=basedo"  enctype="multipart/form-data">

  <div class="form-group">
    <label>名称：</label>
    <input name="title" type="text" class="form-control" value="{$strWish['title']}">
  </div>
  
  
 {if $arrType} 
  <div class="form-group">
    <label>类型：</label>

<select class="form-control" name="typeid">
{loop $arrType $key $item}
<option value="{$item[typeid]}" {if $item[typeid]==$strWish[typeid]}selected="select"{/if}>{$item[typename]}</option>
{/loop}
</select>
  </div>
  
  {/if}

    <div class="form-group">
      <label>封面：</label>
      <div class="">
         <img 
            id="picshow" 
            valign="middle" 
            src="{if $strWish[photo]}{php echo tsXimg($strWish[photo],'wish',500,'',$strWish[path])}{else}{SITE_URL}app/wish/skins/default/wish.jpg{/if}" 
            style="height: 150px;">
         <div style="display: flex;">
           <input type="file" id="picfile" name="picfile">
           <div id="picsubmit" class="btn btn-success">上传照片</button> 
           <input type="hidden" name="photo" id="photo" value="{$strWish['photo']}" />
         </div>
      </div>
    </div>

    <div class="form-group">
      <label>心愿详情：</label>
      <div id="tseditor">{$strWish[content]}</div>
      <div style="display: none;">
        <textarea id="content" name="content">{$strWish[content]}</textarea>
      </div>
      <!--<textarea name="content" id="tseditor"></textarea>-->

    </div>
    <div class="form-group">
      <label>认领期限：</label>
      <p><input class="form-control" name="limittime" readonly value=" {php echo date('Y-m-d H:i',$strWish[limittime])}" id="limitTime" /></p>
    </div>

    <div class="form-group">
      <label>数目：</label>
      <p><input class="form-control" name="quota" value="{$strWish['quota']}" /> </p>
    </div>


    <div class="form-group">
      <label>购买链接：</label>
      <p><input class="form-control" name="link"  value="{$strWish['link']}" /> </p>
    </div>

    <div class="form-group">
      <label>联系人：</label>
      <p><input class="form-control" name="contact" value="{$strWish['contact']}" placeholder="不填则默认为学校联系人" /> </p>
    </div>

    <div class="form-group">
      <label>手机号：</label>
      <p><input class="form-control" name="phone" value="{$strWish['phone']}"  placeholder="不填则默认为学校联系人的电话" /> </p>
    </div>

    <div class="form-group">
      <label>愿主：</label>
      <p><input class="form-control" name="wisher"  value="{$strWish['wisher']}"/> </p>
    </div>


    <div class="form-group">
      <label>所属单位：</label>
      <p>
        <select  name="groupid" id="groupid" class="form-control">
          <option></option>
          {loop $arrGroup $key $item}
          <option value="{$item['groupid']}" {if $item['groupid']==$strWish['groupid']}selected{/if}>{$item['groupname']}</option>
          {/loop}
        </select>
      </p>
    </div>

    <div class="form-group">
      <label>年级：</label>
      <p>

        <select  name="grade" id="grade" class="form-control">
          <option></option>
          <!--{for $i=1;$i<10;$i++}-->
          <option value="{$i}"  {if $strWish['grade']==$i}selected{/if}>{php echo changeNum($i)}年级</option>
          <!--{/for}-->
        </select>
      </p>
    </div>

    <div class="form-group">
      <label>班：</label>
      <p>

        <select  name="class" id="class" class="form-control">
          <option></option>
          <!--{for $i=1;$i<20;$i++}-->
          <option value="{$i}"  {if $strWish['class']==$i}selected{/if}>{$i}班</option>
          <!--{/for}-->
        </select>
      </p>
    </div>
  
  

  <!--
  <div class="form-group">
    <label>心愿海报：</label>
	
{if $strWish['photo']}
<p><img src="{php echo tsXimg($strWish['photo'],'wish','300','200',$strWish['path'])}" /></p>
{/if}
	
    <input type="file" name="photo" />
  </div>
  -->
  
<input type="hidden" name="wishid" value="{$strWish[wishid]}" />
  <input class="btn btn-success" type="submit" value="修改心愿">  <a href="{tsUrl('wish','show',array('id'=>$strWish[wishid]))}">返回</a>
  
</form>

</div>
</div>


</div>
</div>
</div>

{php doAction('tseditor')}

<script src="{SITE_URL}public/js/image.js"></script>
<script>
  function insertGps(dd){
    $('#gps').val(dd);
    $('#myModal').modal('hide');
  }
  function openmap(){
    tsNotice('<iframe frameborder="0" scrolling="no" width="100%" height="400" src="{SITE_URL}index.php?app=wish&ac=add&ts=map"></iframe>');
  }


  $('#beginTime').datetimepicker({
      language:  'zh-CN',
      format: 'yyyy-mm-dd hh:ii'
  });

  $('#limitTime').datetimepicker({
    language:  'zh-CN',
    autoclose: true,
    format: 'yyyy-mm-dd hh:ii'
  });

  $(function(e){
    $('#form1').on('submit', function(e) {
      var title  = $('#title').val();
      var limittime  = $('#limitTime').val();
      var quota  = $('#quota').val();
      var content  = $('#content').val();
      var wisher = $('#wisher').val();
      var groupid = $('#groupid').val();
      var photo = $('#photo').val();


      if(title==''){
        bootbox.alert('名称必填');
        return false;
      }

      if(limittime==''){
        bootbox.alert('到期时间必填');
        return false;
      }

      if(quota==''){
        bootbox.alert('数量必填');
        return false;
      }



      if(wisher==''){
        bootbox.alert('愿主不能为空');
        return false;
      }

      if(groupid==''){
        bootbox.alert('所属单位不能为空');
        return false;
      }

      if(photo==''){
          bootbox.alert('必须上传封面');
          return false;
      }

      if (content == '<p><br></p>') {
        bootbox.alert('内容不能为空');
        return false;
      }

    });

    var picFile = null;
    // 封面上传监听
    $('#picfile').on("change", function (e) {
      $("#photo").val('')
      $("#picshow").attr('src', ''); 

      let file = e.target.files[0]
      compressImg(file, 0.25).then(res => {
        $("#picshow").attr('src', window.URL.createObjectURL(res.file)); 
        picFile = res.file
      })
    });
    
    var upload_url = "{SITE_URL}index.php?app=wish&ac=do&ts=photo";
    $('#picsubmit').on("click", function () {
      if (!picFile) {
        return bootbox.alert('请选择图片！');
      }
      var formData = new FormData();
      formData.append("file", picFile, picFile.filename);
      formData.append("upload_file", true);
      console.log(formData, picFile)
      $.ajax({
        url: upload_url,
        data: formData,
        processData: false,
        contentType: false,
        type: 'POST',
        success: function(data){
          if (data != 0) {
            $("#photo").val(data)
            picFile = null
              return bootbox.alert('图片上传成功！');
          } else {
              return bootbox.alert('图片上传失败！');
          }
        }
      });
    });
  });

</script>


{template footer}